<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生中心 | 教育管理系统</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/chart.js@3.7.1/dist/chart.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --primary-light: #e0e7ff;
            --secondary: #3f37c9;
            --accent: #4895ef;
            --success: #4cc9f0;
            --warning: #f8961e;
            --danger: #f72585;
            --dark: #1e293b;
            --light: #f8fafc;
            --gray: #94a3b8;
            --gray-light: #e2e8f0;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background-color: #f1f5f9;
            color: var(--dark);
            display: flex;
            min-height: 100vh;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 280px;
            background: white;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            display: flex;
            flex-direction: column;
            transition: all 0.3s;
            z-index: 10;
        }

        .sidebar-header {
            padding: 24px;
            border-bottom: 1px solid var(--gray-light);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .logo-icon {
            width: 32px;
            height: 32px;
            background: var(--primary);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 18px;
        }

        .logo-text {
            font-size: 20px;
            font-weight: 600;
            color: var(--dark);
        }

        .sidebar-menu {
            flex: 1;
            padding: 16px 0;
            overflow-y: auto;
        }

        .menu-item {
            padding: 12px 24px;
            margin: 4px 0;
            display: flex;
            align-items: center;
            gap: 12px;
            color: var(--gray);
            text-decoration: none;
            border-radius: 0 12px 12px 0;
            transition: all 0.2s;
        }

        .menu-item:hover {
            background: var(--primary-light);
            color: var(--primary);
        }

        .menu-item.active {
            background: var(--primary-light);
            color: var(--primary);
            position: relative;
        }

        .menu-item.active::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            width: 4px;
            background: var(--primary);
            border-radius: 0 4px 4px 0;
        }

        .menu-item i {
            font-size: 18px;
            width: 24px;
            text-align: center;
        }

        .sidebar-footer {
            padding: 16px;
            border-top: 1px solid var(--gray-light);
        }

        .user-profile {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 8px 12px;
            border-radius: 8px;
            transition: all 0.2s;
        }

        .user-profile:hover {
            background: var(--gray-light);
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--primary-light);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
            font-weight: 600;
            overflow: hidden;
        }

        .user-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .user-info {
            flex: 1;
        }

        .user-name {
            font-size: 14px;
            font-weight: 500;
            color: var(--dark);
        }

        .user-role {
            font-size: 12px;
            color: var(--gray);
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .topbar {
            height: 70px;
            background: white;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 24px;
            z-index: 5;
        }

        .search-bar {
            position: relative;
            width: 400px;
        }

        .search-bar input {
            width: 100%;
            padding: 10px 16px 10px 40px;
            border: 1px solid var(--gray-light);
            border-radius: 8px;
            font-size: 14px;
            transition: all 0.2s;
        }

        .search-bar input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
        }

        .search-bar i {
            position: absolute;
            left: 12px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--gray);
        }

        .topbar-actions {
            display: flex;
            align-items: center;
            gap: 16px;
        }

        .notification-btn, .message-btn {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: var(--gray-light);
            color: var(--dark);
            position: relative;
            cursor: pointer;
            transition: all 0.2s;
        }

        .notification-btn:hover, .message-btn:hover {
            background: var(--primary-light);
            color: var(--primary);
        }

        .notification-badge {
            position: absolute;
            top: -4px;
            right: -4px;
            width: 18px;
            height: 18px;
            background: var(--danger);
            color: white;
            border-radius: 50%;
            font-size: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .content-wrapper {
            flex: 1;
            padding: 24px;
            overflow-y: auto;
        }

        .welcome-banner {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 24px;
            border-radius: 12px;
            margin-bottom: 24px;
            position: relative;
            overflow: hidden;
        }

        .welcome-banner::before {
            content: '';
            position: absolute;
            top: -50px;
            right: -50px;
            width: 200px;
            height: 200px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
        }

        .welcome-banner h1 {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 8px;
        }

        .welcome-banner p {
            font-size: 14px;
            opacity: 0.9;
            max-width: 60%;
        }

        .stats-cards {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
            gap: 16px;
            margin-bottom: 24px;
        }

        .stat-card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
            transition: all 0.2s;
        }

        .stat-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.05);
        }

        .stat-card-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 12px;
        }

        .stat-card-title {
            font-size: 14px;
            color: var(--gray);
        }

        .stat-card-icon {
            width: 40px;
            height: 40px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
        }

        .stat-card-value {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 4px;
        }

        .stat-card-diff {
            font-size: 12px;
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .stat-card-diff.positive {
            color: var(--success);
        }

        .stat-card-diff.negative {
            color: var(--danger);
        }

        .main-grid {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 24px;
        }

        .card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        }

        .card-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 16px;
        }

        .card-title {
            font-size: 18px;
            font-weight: 600;
        }

        .card-actions {
            display: flex;
            gap: 8px;
        }

        .card-action-btn {
            width: 32px;
            height: 32px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: var(--gray-light);
            color: var(--dark);
            cursor: pointer;
            transition: all 0.2s;
        }

        .card-action-btn:hover {
            background: var(--primary-light);
            color: var(--primary);
        }

        .course-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .course-item {
            display: flex;
            align-items: center;
            padding: 12px;
            border-radius: 8px;
            transition: all 0.2s;
            cursor: pointer;
        }

        .course-item:hover {
            background: var(--gray-light);
        }

        .course-icon {
            width: 40px;
            height: 40px;
            border-radius: 8px;
            background: var(--primary-light);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
            margin-right: 12px;
            font-size: 18px;
        }

        .course-info {
            flex: 1;
        }

        .course-name {
            font-size: 14px;
            font-weight: 500;
            margin-bottom: 2px;
        }

        .course-meta {
            font-size: 12px;
            color: var(--gray);
            display: flex;
            gap: 8px;
        }

        .course-progress {
            height: 4px;
            background: var(--gray-light);
            border-radius: 2px;
            margin-top: 6px;
            overflow: hidden;
        }

        .progress-bar {
            height: 100%;
            background: var(--primary);
            border-radius: 2px;
        }

        .notification-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .notification-item {
            display: flex;
            gap: 12px;
            padding: 12px;
            border-radius: 8px;
            transition: all 0.2s;
            cursor: pointer;
        }

        .notification-item:hover {
            background: var(--gray-light);
        }

        .notification-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--primary-light);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
            font-size: 16px;
        }

        .notification-info {
            flex: 1;
        }

        .notification-title {
            font-size: 14px;
            font-weight: 500;
            margin-bottom: 4px;
        }

        .notification-desc {
            font-size: 12px;
            color: var(--gray);
        }

        .notification-time {
            font-size: 10px;
            color: var(--gray);
            margin-top: 4px;
        }

        .chart-container {
            height: 300px;
            margin-top: 16px;
        }

        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 200px;
            color: var(--gray);
        }

        @media (max-width: 1200px) {
            .main-grid {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 768px) {
            .sidebar {
                width: 80px;
            }
            .logo-text, .menu-item span, .user-info {
                display: none;
            }
            .search-bar {
                width: 200px;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 -->
<div class="sidebar">
    <div class="sidebar-header">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-graduation-cap"></i>
            </div>
            <span class="logo-text">EduSys</span>
        </div>
    </div>

    <div class="sidebar-menu">
        <a href="${pageContext.request.contextPath}/student/home" class="menu-item active">
            <i class="fas fa-home"></i>
            <span>仪表盘</span>
        </a>
        <a href="${pageContext.request.contextPath}/student/courses" class="menu-item">
            <i class="fas fa-book-open"></i>
            <span>我的课程</span>
        </a>
        <a href="${pageContext.request.contextPath}/student/schedule" class="menu-item">
            <i class="fas fa-calendar-alt"></i>
            <span>课程表</span>
        </a>
        <a href="${pageContext.request.contextPath}/student/assignments" class="menu-item">
            <i class="fas fa-tasks"></i>
            <span>作业</span>
        </a>
        <a href="${pageContext.request.contextPath}/student/grades" class="menu-item">
            <i class="fas fa-chart-line"></i>
            <span>成绩</span>
        </a>
        <a href="${pageContext.request.contextPath}/student/discussions" class="menu-item">
            <i class="fas fa-comments"></i>
            <span>讨论</span>
        </a>
        <a href="${pageContext.request.contextPath}/student/settings" class="menu-item">
            <i class="fas fa-cog"></i>
            <span>设置</span>
        </a>
    </div>

    <div class="sidebar-footer">
        <div class="user-profile">
            <div class="user-avatar">
                <c:choose>
                    <c:when test="${not empty dashboard.student.avatar}">
                        <img src="${dashboard.student.avatar}" alt="用户头像">
                    </c:when>
                    <c:otherwise>
                        ${fn:substring(dashboard.student.name, 0, 1)}
                    </c:otherwise>
                </c:choose>
            </div>
            <div class="user-info">
                <div class="user-name">${dashboard.student.name}</div>
                <div class="user-role">${dashboard.student.major}</div>
            </div>
            <i class="fas fa-chevron-down"></i>
        </div>
    </div>
</div>

<!-- 主内容区域 -->
<div class="main-content">
    <!-- 顶部导航栏 -->
    <div class="topbar">
        <div class="search-bar">
            <i class="fas fa-search"></i>
            <input type="text" placeholder="搜索课程、作业...">
        </div>

        <div class="topbar-actions">
            <div class="notification-btn">
                <i class="fas fa-bell"></i>
                <c:if test="${not empty dashboard.notifications && dashboard.notifications.size() > 0}">
                    <div class="notification-badge">${dashboard.notifications.size()}</div>
                </c:if>
            </div>
            <div class="message-btn">
                <i class="fas fa-envelope"></i>
            </div>
        </div>
    </div>

    <!-- 内容区域 -->
    <div class="content-wrapper">
        <c:choose>
            <c:when test="${empty dashboard}">
                <div class="loading">
                    <i class="fas fa-spinner fa-spin"></i> 数据加载中...
                </div>
            </c:when>
            <c:otherwise>
                <!-- 欢迎横幅 -->
                <div class="welcome-banner">
                    <h1>${empty dashboard.student.name ? '您好' : dashboard.student.name}同学！</h1>
                    <p>
                        今天是<fmt:formatDate value="<%=new java.util.Date()%>" pattern="yyyy年MM月dd日 E"/>。
                        您有${dashboard.courseCount}节课程和${dashboard.assignmentCount}个待完成作业。
                    </p>
                </div>

                <!-- 统计卡片 -->
                <div class="stats-cards">
                    <div class="stat-card">
                        <div class="stat-card-header">
                            <div class="stat-card-title">进行中课程</div>
                            <div class="stat-card-icon" style="background: rgba(67, 97, 238, 0.1); color: var(--primary);">
                                <i class="fas fa-book"></i>
                            </div>
                        </div>
                        <div class="stat-card-value">${dashboard.courseCount}</div>
                        <div class="stat-card-diff positive">
                            <i class="fas fa-arrow-up"></i>
                            <span>比上学期多2门</span>
                        </div>
                    </div>

                    <div class="stat-card">
                        <div class="stat-card-header">
                            <div class="stat-card-title">待完成作业</div>
                            <div class="stat-card-icon" style="background: rgba(248, 113, 113, 0.1); color: var(--danger);">
                                <i class="fas fa-tasks"></i>
                            </div>
                        </div>
                        <div class="stat-card-value">${dashboard.assignmentCount}</div>
                        <div class="stat-card-diff negative">
                            <i class="fas fa-arrow-up"></i>
                            <span>比上周多1个</span>
                        </div>
                    </div>

                    <div class="stat-card">
                        <div class="stat-card-header">
                            <div class="stat-card-title">平均成绩</div>
                            <div class="stat-card-icon" style="background: rgba(16, 185, 129, 0.1); color: var(--success);">
                                <i class="fas fa-star"></i>
                            </div>
                        </div>
                        <div class="stat-card-value"><fmt:formatNumber value="${dashboard.avgScore}" pattern="#.##"/></div>
                        <div class="stat-card-diff positive">
                            <i class="fas fa-arrow-up"></i>
                            <span>比上学期高2.3分</span>
                        </div>
                    </div>

                    <div class="stat-card">
                        <div class="stat-card-header">
                            <div class="stat-card-title">出勤率</div>
                            <div class="stat-card-icon" style="background: rgba(245, 158, 11, 0.1); color: var(--warning);">
                                <i class="fas fa-calendar-check"></i>
                            </div>
                        </div>
                        <div class="stat-card-value">${dashboard.attendanceRate}</div>
                        <div class="stat-card-diff positive">
                            <i class="fas fa-arrow-up"></i>
                            <span>比上学期高3%</span>
                        </div>
                    </div>
                </div>

                <!-- 主要内容网格 -->
                <div class="main-grid">
                    <!-- 左侧主要内容 -->
                    <div>
                        <!-- 课程列表卡片 -->
                        <div class="card">
                            <div class="card-header">
                                <div class="card-title">我的课程</div>
                                <div class="card-actions">
                                    <div class="card-action-btn">
                                        <i class="fas fa-ellipsis-h"></i>
                                    </div>
                                </div>
                            </div>

                            <div class="course-list">
                                <c:forEach items="${dashboard.courses}" var="course">
                                    <div class="course-item">
                                        <div class="course-icon">
                                            <i class="fas ${course.iconClass != null ? course.iconClass : 'fa-book'}"></i>
                                        </div>
                                        <div class="course-info">
                                            <div class="course-name">${course.name}</div>
                                            <div class="course-meta">
                                                <span>${course.teacher}</span>
                                                <span>${course.schedule}</span>
                                            </div>
                                            <div class="course-progress">
                                                <div class="progress-bar" style="width: ${course.progress}%;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                        </div>

                        <!-- 成绩趋势图表 -->
                        <div class="card" style="margin-top: 24px;">
                            <div class="card-header">
                                <div class="card-title">成绩趋势</div>
                                <div class="card-actions">
                                    <div class="card-action-btn">
                                        <i class="fas fa-download"></i>
                                    </div>
                                    <div class="card-action-btn">
                                        <i class="fas fa-ellipsis-h"></i>
                                    </div>
                                </div>
                            </div>

                            <div class="chart-container">
                                <canvas id="performanceChart"></canvas>
                            </div>
                        </div>
                    </div>

                    <!-- 右侧边栏 -->
                    <div>
                        <!-- 近期作业 -->
                        <div class="card">
                            <div class="card-header">
                                <div class="card-title">近期作业</div>
                                <div class="card-actions">
                                    <div class="card-action-btn">
                                        <i class="fas fa-ellipsis-h"></i>
                                    </div>
                                </div>
                            </div>

                            <div class="course-list">
                                <c:forEach items="${dashboard.assignments}" var="assignment">
                                    <div class="course-item">
                                        <div class="course-icon" style="background: rgba(${assignment.urgent ? '248, 113, 113' : '245, 158, 11'}, 0.1); color: var(${assignment.urgent ? '--danger' : '--warning'});">
                                            <i class="fas fa-exclamation"></i>
                                        </div>
                                        <div class="course-info">
                                            <div class="course-name">${assignment.name}</div>
                                            <div class="course-meta">
                                                <span>截止: <fmt:formatDate value="${assignment.deadline}" pattern="MM月dd日 HH:mm"/></span>
                                            </div>
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                        </div>

                        <!-- 通知 -->
                        <div class="card" style="margin-top: 24px;">
                            <div class="card-header">
                                <div class="card-title">最新通知</div>
                                <div class="card-actions">
                                    <div class="card-action-btn">
                                        <i class="fas fa-ellipsis-h"></i>
                                    </div>
                                </div>
                            </div>

                            <div class="notification-list">
                                <c:forEach items="${dashboard.notifications}" var="notification">
                                    <div class="notification-item">
                                        <div class="notification-icon">
                                            <i class="fas ${notification.type == 'SYSTEM' ? 'fa-bullhorn' : notification.type == 'COURSE' ? 'fa-book' : 'fa-user-friends'}"></i>
                                        </div>
                                        <div class="notification-info">
                                            <div class="notification-title">${notification.title}</div>
                                            <div class="notification-desc">${notification.content}</div>
                                            <div class="notification-time">
                                                <fmt:formatDate value="${notification.createTime}" pattern="yyyy-MM-dd HH:mm"/>
                                            </div>
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                        </div>
                    </div>
                </div>
            </c:otherwise>
        </c:choose>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js@3.7.1/dist/chart.min.js"></script>
<script>
    // 初始化成绩趋势图表
    const ctx = document.getElementById('performanceChart')?.getContext('2d');
    if (ctx) {
        const performanceChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ['9月', '10月', '11月', '12月', '1月', '2月'],
                datasets: [
                    <c:forEach items="${dashboard.performance}" var="perf" varStatus="loop">
                    {
                        label: '${perf.courseName}',
                        data: [${perf.scores}],
                        borderColor: getChartColor(${loop.index}),
                        backgroundColor: getChartColor(${loop.index}, 0.1),
                        tension: 0.3,
                        fill: true
                    }${!loop.last ? ',' : ''}
                    </c:forEach>
                ]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        position: 'top',
                    },
                    tooltip: {
                        mode: 'index',
                        intersect: false,
                    }
                },
                scales: {
                    y: {
                        beginAtZero: false,
                        min: 70,
                        max: 100
                    }
                },
                interaction: {
                    mode: 'nearest',
                    axis: 'x',
                    intersect: false
                }
            }
        });
    }

    function getChartColor(index, opacity = 1) {
        const colors = ['#4361ee', '#4cc9f0', '#f8961e', '#f72585'];
        if (opacity < 1) {
            const hex = colors[index % colors.length].replace('#', '');
            const r = parseInt(hex.substring(0, 2), g = parseInt(hex.substring(2, 4)), b = parseInt(hex.substring(4, 6)));
            return `rgba(${r}, ${g}, ${b}, ${opacity})`;
        }
        return colors[index % colors.length];
    }
</script>
</body>
</html>